from sqlalchemy import Column, String, Integer, Text, DateTime, SmallInteger
from sqlalchemy.orm import relationship

from config.mysql_config import Base
from datetime import datetime

class Type(Base):
    """PPT种类表"""
    __tablename__ = 'type'

    type_id = Column(Integer, primary_key=True, autoincrement=True)
    type_name = Column(String(100), unique=True, nullable=False)
    del_flag = Column(SmallInteger, default=0)

    # 反向引用：type.ppts 可访问所有该类型的PPT列表
    ppts = relationship('PPT', back_populates='type', cascade="all, delete-orphan", order_by='PPT.ppt_id')

    def __repr__(self):
        return f"<Type(type_id={self.type_id}, type_name='{self.type_name}')>"

    def to_dict(self):
        return {
            "type_id": self.type_id,
            "type_name": self.type_name,
            "del_flag": self.del_flag
        }
